package com.wustl.android.hood;

import java.io.IOException;

import android.app.Activity;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.widget.TextView;

public class TwitterMain extends Activity{

	private String _updateText;
    private String _twitterUserName;
    private String _twitterUserPassword;

	public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.twitter);
        
        Button button = (Button)findViewById(R.id.update_tweet);
        button.setOnClickListener(mUpdateTweetListener);
               
        _twitterUserName = "hood_on_android";
        _twitterUserPassword = "android";
        _updateText = "Hello world";
        
        try {
        	//TODO doesn't work. still figuring out basic debugging.
        	TwitterConnection.sendTwitterUpdate(_twitterUserName, _twitterUserPassword, _updateText);		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
    // Create an anonymous class to act as a button click listener.
    private OnClickListener mUpdateTweetListener = new OnClickListener()
    {
        public void onClick(View v)
        {
            // To send a result, simply call setResult() before your
            // activity is finished.
         	StringBuffer sb = new StringBuffer();
        	TextView edit = (TextView) findViewById(R.id.tweet);
        	edit.setText(sb);
        	_updateText = sb.toString();
        	
            try {
            	//TODO doesn't work. still figuring out basic debugging.
            	TwitterConnection.sendTwitterUpdate(_twitterUserName, _twitterUserPassword, _updateText);		
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

            finish();
        }
    };

}
